package SpaceIT.components;

import java.net.URI;
import java.net.URISyntaxException;

import model.pojo.NhanVien;

import org.apache.tapestry5.BindingConstants;
import org.apache.tapestry5.Block;
import org.apache.tapestry5.ComponentResources;
import org.apache.tapestry5.annotations.ApplicationState;
import org.apache.tapestry5.annotations.IncludeStylesheet;
import org.apache.tapestry5.annotations.Parameter;
import org.apache.tapestry5.annotations.Persist;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.annotations.SessionState;
import org.apache.tapestry5.ioc.Messages;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.apache.tapestry5.services.Session;

import controller.util.ControllerHelper;

@IncludeStylesheet("context:layout/css/style.css")
public class layoutAdmin {
	/** The page title, for the <title> element and the <h1> element. */
    @Property
    @Parameter(required = true, defaultPrefix = BindingConstants.LITERAL)
    private String title;

    @Property
    private String pageName;

    @Property
    @Parameter(defaultPrefix = BindingConstants.LITERAL)
    private String sidebarTitle;

    @Property
    @Parameter(defaultPrefix = BindingConstants.LITERAL)
    private Block sidebar;

    @Inject
    private ComponentResources resources;

    public String getClassForPageName()
    {
      return resources.getPageName().equalsIgnoreCase(pageName)
             ? "current_page_item"
             : null;
    }

    public String[] getPageNames()
    {
      return new String[] { "Index", "About", "Contact" };
    }
    @Inject
    private Messages messages;
	
    public layoutAdmin() {
    //  {
    		try 
    		{
    			URI xmlPath = messages.getClass().getResource("connect.xml").toURI();
    			URI propPath = messages.getClass().getResource("SP.properties").toURI();
    			ControllerHelper.napThongTinKetNoi(xmlPath.getPath() , propPath.getPath());
    			//NV.setDangNhap(true);
    		} 
    		catch (URISyntaxException e) {
    			// TODO Auto-generated catch block
    			//e.printStackTrace();
    		}
    } 
  
    @ApplicationState
    private NhanVien NV;
    
    public boolean isDangNhap()
    {
    	if(NV.isDangNhap()==false)
    	{
    		return false;
    	}
    	return true;
    }
}
